package me.xplabs.utils 
{
	import flash.display.Bitmap;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.utils.Dictionary;
	import flash.utils.getDefinitionByName;
	import flash.utils.getQualifiedClassName;
	/**
	 * 大量的对象管理对象池
	 * ...
	 * @author xiaohan
	 */
	public class MacroObjPool 
	{
		
		private static var pool:Dictionary = new Dictionary();
		private static var buf:*;
		public function MacroObjPool() 
		{
			
		}
		
		
		public static function getObj(cla:Class,maxSize:int=50,growthValue:uint=10):* 
		{
			buf = pool[cla];
			if (buf == null) 
			{
				buf = new SimpleObjPool(cla, maxSize, growthValue);
				pool[cla] = buf;
			}
			return buf.getObj();
		}
		
		public static function dispose(obj:*):void
		{
			buf = pool[getDefinitionByName(getQualifiedClassName(obj))];
			if (buf != null) buf.dispose(obj);
			else
			{
				buf = new SimpleObjPool(Class(getDefinitionByName(getQualifiedClassName(obj))), 50, 10);
				pool[getDefinitionByName(getQualifiedClassName(obj))] = buf;
				buf.dispose(obj);
			}
			if (obj is Bitmap)
			{
				obj.scaleX = obj.scaleY = 1;
				obj.bitmapData = null;
			}else if(obj is Shape)
			{
				Shape(obj).graphics.clear();
			}
			obj = null;
		}
		
	}

}